// @flow
import React from 'react'
import { DatePicker, Icon } from 'antd'
import styles from './DateSelect.css'

class DateSelect extends React.Component {
  state = {
    date: null
  }
  addDate = () => {
    const { date } = this.state
    if (date) {
      const newDate = date.add(1, 'd')
      this.setState({
        date: newDate
      })
    }
  }
  subDate = () => {
    const { date } = this.state
    if (date) {
      const newDate = date.subtract(1, 'd')
      this.setState({
        date: newDate
      })
    }
  }
  changeDate = (date: any) => {
    this.setState({
      date: date
    })
    this.props.onChange(date)
  }
  render () {
    const { date } = this.state
    return (
      <div className={styles['dateCon']}>
        <Icon type='left-circle' onClick={this.subDate} className={styles['dateIcon']} />
        <DatePicker
          value={date}
          onChange={this.changeDate}
          style={{ width:100, position:'absolute', top:0, left:30 }}
        />
        <Icon type='right-circle' onClick={this.addDate} className={styles['dateIcon']} style={{ left:120 }} />
      </div>
    )
  }
}

export default DateSelect
